var ca = document.cookie.split(';');
var result = '';
var cc = '';
var bb = 0;
var indexs = ca.length;
$(document).ready(function() {
	getCookie();
});
function setCookie(cname, cvalue, exdays) {
	var d = new Date();
	d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
	var expires = "expires=" + d.toGMTString();
	document.cookie = cname + "=" + cvalue + "; " + expires;
}

function getCookie() {
	var list = $(".historyS");
	if(document.cookie.length > 0) {
		for(var i = 0; i < ca.length; i++) {
			var c = ca[i].trim();
			var ca1 = c.split('=');
			cc = ca1[1];
			result += "<a href='#'>" + cc + "</a>";
		}
		list.html(result);
	} else {
		list.html("<p>暂无搜索记录</p>");
	}

}
$('.headerRw').click(function() {
	var value0 = '';
	var list = $(".historyS");
	var cvalue = $('.searc input').val();
	if(cvalue != "" && cvalue != null) {
		var arr = $('.historyS a'),
			temp = [];
		for(var i = 0; i < arr.length; i++) {
			temp.push(arr[i].innerHTML)
		}
		if(temp.indexOf(cvalue) == -1) {
			
			var indexs = $(".historyS a").length;
			if(indexs>9){
				bb=parseInt(9*Math.random());
				alert(bb);
				$('.historyS a').eq(bb).remove();
				list.append("<a href='#'>" + cvalue + "</a>");
				setCookie(bb+1, cvalue, 30);
			}else{
				result += "<a href='#'>" + cvalue + "</a>";
			    list.html(result);
			    indexs = $(".historyS a").length;
			    var cname = indexs;
				setCookie(cname, cvalue, 30);
			}
		}

	}
});

//搜索页面
//删除
$('.searchI').click(function(){
	$('.mengban').css({display:'block',height:'150%'});
	$('.searchT').css({display:'block'});
	$('body').css({overflow:'hidden'});
	$('html').css({overflow:'hidden'});
});
$('.searchT a:nth-child(2)').click(function(){
	$('.mengban').css({display:'none'});
	$('.searchT').css({display:'none'});
	$('body').css({overflow:'visible'});
	$('html').css({overflow:'visible'});
});
$('.searchT a:nth-child(3)').click(function(){
	$('.mengban').css({display:'none'});
	$('.searchT').css({display:'none'});
	for (var i=0;i<10;i++) {
			setCookie(i+1, '', 0);
			$('.historyS a').remove();
			$('.historyS ').html("<p>暂无搜索记录</p>");
		
	}
	$('body').css({overflow:'visible'});
	$('html').css({overflow:'visible'});
});
